class Solution {
	public String replaceSpace(String s) {
		int count = 0;
		for(int i = 0; i < s.length(); i++) {
			if(s.charAt(i) == ' ') {
				count++;
			}
		}
		int new_length = s.length() + count * 2;
		int target = 0;
		char[] chars = new char[new_length];
		for(int i = 0; i < s.length(); i++) {
			char c = s.charAt(i);
			if(c == ' ') {
				chars[target++] = '%';
				chars[target++] = '2';
				chars[target++] = '0';
			}
			else{
				chars[target++] = c;
			}
		}
		return new String(chars, 0, target);
	}
}